<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分享到</title>
    <style>
        #div1{
            width: 150px;
            height: 200px;
            background: green;
            position: absolute;
            left: -150px;
        }
        #div1 span{
            position: absolute;
            width: 20px;
            height: 60px;
            line-height: 20px;
            background: #276cff;
            right: -20px;
            top: 70px;
        }
    </style>
    <script>
        window.onload = function () {
            var oDiv=document.getElementById('div1');
            oDiv.onmouseover=function () {
                starMove(0,10);
            };
            oDiv.onmouseout=function () {
                starMove(-150,-10);
            };
        };

        var  timer;
        function starMove (iTarget,speed) {
            var oDiv = document.getElementById('div1');  //获取div1
            clearInterval(timer);   //开始运动时关闭原有定时器，否则再次点击时会再次开启新得定时器，从而程序出现bug
            timer = setInterval(function () {
                if (oDiv.offsetLeft==iTarget)
                {
                    clearInterval(timer);
                }
                else {
                    oDiv.style.left=oDiv.offsetLeft+speed+'px';
                }
            },30);
        }

    </script>
</head>
<body>
<div id="div1">
    <span>分享到</span>
</div>

</body>
</html>